package com.bzxhh;

import java.math.BigDecimal;

public class BigDecimalTest {

    public static void main(String[] args) {
        System.out.println(0.1 + 0.2);
        System.out.println(0.4 - 0.1);
        System.out.println(0.1 * 0.2);
        System.out.println(0.3 / 0.1);

        System.out.println("========================");

        BigDecimal intStr = new BigDecimal("22");
        BigDecimal doubleStr = new BigDecimal(1.1111);
        BigDecimal doubleStr2 = new BigDecimal(100);

        System.out.println(intStr);
        System.out.println(doubleStr);
        System.out.println(doubleStr2);

        System.out.println("========================");

        intStr = new BigDecimal("3.6666");
        doubleStr = new BigDecimal(Double.toString(3.6666));

        System.out.println(intStr);
        System.out.println(doubleStr);

        System.out.println("========================");

        intStr = new BigDecimal("3.6666");
        doubleStr = BigDecimal.valueOf(3.6666);

        System.out.println(intStr);
        System.out.println(doubleStr);

        System.out.println("========================");

        double result = new BigDecimal(Double.toString(1.2333))
                .divide(new BigDecimal(Float.toString(3.3f)), 6, BigDecimal.ROUND_HALF_UP)
                .doubleValue();
        System.out.println(result);

        double result2 = new BigDecimal(Double.toString(10))
                .divide(new BigDecimal(Float.toString(3f)),2,BigDecimal.ROUND_HALF_UP)
                .doubleValue();
        System.out.println(result2);
    }
}
